package com.cn.qgx428.orderingmeal.adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.cn.qgx428.orderingmeal.R;
import com.cn.qgx428.orderingmeal.myClass.Bankcard;
import com.cn.qgx428.orderingmeal.viewHolder.RViewHolder;

import java.util.List;

/**
 * Created by QinX on 2017/5/17.
 */

public class PayCardOptionsAdapter extends RBaseAdapter {

    private onCardNOOclickListener listener;

    public interface onCardNOOclickListener{
        void onClick(String cardNO);
    }

    public PayCardOptionsAdapter(Context context, List list, int itemLayoutId) {
        super(context, list, itemLayoutId);
    }

    @Override
    public void convert(final RViewHolder holder, Object item) {
        final TextView cardNO = holder.getView(R.id.pay_card_item_no);
        Bankcard card = (Bankcard) item;
        String NO = changeCardNO(((Bankcard) item).getCardID());
        cardNO.setText(NO);
        if (listener != null){
            cardNO.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    listener.onClick(cardNO.getText().toString());
                }
            });
        }

    }

    private String changeCardNO(String cardID) {
        String str = cardID.replace(" ","");
        str = str.substring(0,4)+" **** **** "+str.substring(str.length()-4, str.length());
        return str;
    }

    public void setCardOnclickListener (onCardNOOclickListener listener){
        this.listener = listener;
    }
}
